//
//  WillPayRulerTableViewCell.m
//  Jlcf_ios
//
//  Created by zl on 2018/10/18.
//  Copyright © 2018年 ski. All rights reserved.
//

#import "WdoaAoJLCFWillPayRulerTableViewCellcaiIvs.h"
#import "JLCFTTScrollRulerView.h"
@interface WdoaAoJLCFWillPayRulerTableViewCellcaiIvs ()<rulerDelegate, UITextFieldDelegate>

@property (nonatomic,strong) JLCFTTScrollRulerView *ruler;

@property (nonatomic, strong) UITextField *KfiJgNaccountTextFieldQccsSJ;

@property (nonatomic, strong) UILabel *titleLabel;

@property (nonatomic, strong) UILabel *DqlqILaprLabelIPueGU;

@property (nonatomic, strong) UILabel *ItygvTaprTipsLabelOisWqX;


@property (nonatomic, strong) UILabel *qnAAhxnianhuaLabelffIRNe;
@property (nonatomic, strong) UILabel *edHyphtipsLabelTVYPVW;


@end
@implementation WdoaAoJLCFWillPayRulerTableViewCellcaiIvs

- (void)reloadData{
    
    if(!self.qnAAhxnianhuaLabelffIRNe){
        self.qnAAhxnianhuaLabelffIRNe = [UILabel new];
        self.qnAAhxnianhuaLabelffIRNe.top = 11;
        self.qnAAhxnianhuaLabelffIRNe.left = 21;
        [self addSubview:self.qnAAhxnianhuaLabelffIRNe];
    }
    if (self.qnAAhxnianhuaLabelffIRNe) {
        self.qnAAhxnianhuaLabelffIRNe.textColor =QTZ_Black;
        self.qnAAhxnianhuaLabelffIRNe.font = FONT(9);
        self.qnAAhxnianhuaLabelffIRNe.text = [NSString stringWithFormat:@"%@天预期年化%@%%",self.CUWORhdetailModelIRREMd.data.timeLimitDay,self.CUWORhdetailModelIRREMd.data.apr];
        [self.qnAAhxnianhuaLabelffIRNe sizeToFit];
    }
    if (!self.edHyphtipsLabelTVYPVW) {
        self.edHyphtipsLabelTVYPVW = [UILabel new];
        self.edHyphtipsLabelTVYPVW.top = self.qnAAhxnianhuaLabelffIRNe.top;
        self.edHyphtipsLabelTVYPVW.left = self.qnAAhxnianhuaLabelffIRNe.right +10;
        [self addSubview:self.edHyphtipsLabelTVYPVW];
        
    }
    
    if (self.edHyphtipsLabelTVYPVW) {
        self.edHyphtipsLabelTVYPVW.text = @"起购金额100元，100的倍数递增";
        self.edHyphtipsLabelTVYPVW.textColor = QTZ_Gray200;
        self.edHyphtipsLabelTVYPVW.font = FONT(9);
        [self.edHyphtipsLabelTVYPVW sizeToFit];
    }
    
    if (!self.titleLabel) {
        self.titleLabel = [UILabel labelWithText:@"我要投资（元）" textColor:QTZ_Gray118 font:FONT(12)];
        self.titleLabel.centerX = FULL_WIDTH / 2;
        self.titleLabel.top = self.qnAAhxnianhuaLabelffIRNe.bottom + 12;
        [self addSubview:self.titleLabel];
    }
    
    if (!self.KfiJgNaccountTextFieldQccsSJ) {
        self.KfiJgNaccountTextFieldQccsSJ = [[UITextField alloc] initWithFrame:CGRectMake(0, 0, 120, 30)];
        self.KfiJgNaccountTextFieldQccsSJ.textColor = QTZ_Black;
        self.KfiJgNaccountTextFieldQccsSJ.centerX = self.titleLabel.centerX;
        self.KfiJgNaccountTextFieldQccsSJ.top = self.titleLabel.bottom + 5;
        self.KfiJgNaccountTextFieldQccsSJ.textAlignment = NSTextAlignmentCenter;
        self.KfiJgNaccountTextFieldQccsSJ.font = FONT(30);
        self.KfiJgNaccountTextFieldQccsSJ.delegate = self;
        self.KfiJgNaccountTextFieldQccsSJ.keyboardType = UIKeyboardTypeNumbersAndPunctuation;
        self.KfiJgNaccountTextFieldQccsSJ.returnKeyType = UIReturnKeyDone;
        [self.KfiJgNaccountTextFieldQccsSJ.layer addSublayer:[self addLineOriginPoint:CGPointMake(0.0f, self.KfiJgNaccountTextFieldQccsSJ.frame.size.height) toPoint:CGPointMake( self.KfiJgNaccountTextFieldQccsSJ.frame.size.width, self.KfiJgNaccountTextFieldQccsSJ.frame.size.height) color:QTZ_Black borderWidth:1.f]];
        [self addSubview:self.KfiJgNaccountTextFieldQccsSJ];
    }
    
    
    
    if (!self.ruler) {
        self.ruler = [[JLCFTTScrollRulerView alloc] initWithFrame:CGRectMake(10, 100, FULL_WIDTH - 20, 100)];//
        self.ruler.rulerHeight = 40;
        self.ruler.rulerDelegate = self;
        self.ruler.lockMin = 0;
        self.ruler.h_height = 25;
        self.ruler.m_height = 12;
        self.ruler.pointerBackgroundColor = QTZ_Black;
        [self.ruler setPointerFrame:CGRectMake(self.ruler.pointerFrame.origin.x, -5, self.ruler.pointerFrame.size.width, self.ruler.pointerFrame.size.height)];
        self.ruler.lockDefault = 100;
        //在执行此方法前，可先设定参数：最小值，最大值，横向，纵向等等  ------若不设定，则按照默认值绘制
        [self.ruler classicRuler];
        [self addSubview:self.ruler];
        
        
        [self.ruler scrollToValue:0 animation:YES];
    }
    
    if (self.ruler) {
        if (self.CUWORhdetailModelIRREMd) {
            self.ruler.lockMin = [self.CUWORhdetailModelIRREMd.data.lowestAccount integerValue];
            self.ruler.lockMax = [self.CUWORhdetailModelIRREMd.data.remmoney integerValue];
            self.ruler.unitValue = 100;
            [self.ruler reDrawerRuler];
        }
    }
    
    if (!self.DqlqILaprLabelIPueGU) {
        self.DqlqILaprLabelIPueGU = [UILabel new];
        self.DqlqILaprLabelIPueGU.textColor = QTZ_Black;
        self.DqlqILaprLabelIPueGU.font = FONT(12);
        [self addSubview:self.DqlqILaprLabelIPueGU];
    }
    
    if (self.DqlqILaprLabelIPueGU) {
        self.DqlqILaprLabelIPueGU.text = @"0.00";
        [self.DqlqILaprLabelIPueGU sizeToFit];
        self.DqlqILaprLabelIPueGU.centerX = self.KfiJgNaccountTextFieldQccsSJ.centerX;
        self.DqlqILaprLabelIPueGU.top = self.ruler.centerY + 10;
    }
    
    if (!self.ItygvTaprTipsLabelOisWqX) {
        self.ItygvTaprTipsLabelOisWqX = [UILabel new];
        self.ItygvTaprTipsLabelOisWqX.textColor = QTZ_Gray153;
        self.ItygvTaprTipsLabelOisWqX.font = FONT(9);
        [self addSubview:self.ItygvTaprTipsLabelOisWqX];
    }
    
    if (self.ItygvTaprTipsLabelOisWqX) {
        self.ItygvTaprTipsLabelOisWqX.text = [NSString stringWithFormat:@"预计%@后收益（元）",self.CUWORhdetailModelIRREMd.data.endday];
        [self.ItygvTaprTipsLabelOisWqX sizeToFit];
        self.ItygvTaprTipsLabelOisWqX.centerX = self.KfiJgNaccountTextFieldQccsSJ.centerX;
        self.ItygvTaprTipsLabelOisWqX.top = self.ruler.centerY + 30;
    }
}

- (void)rulerWith:(NSInteger)value
{
    self.KfiJgNaccountTextFieldQccsSJ.text = [NSString stringWithFormat:@"%ld", (long)value];
    self.DqlqILaprLabelIPueGU.text = [NSString stringWithFormat:@"%.2f", value * [self.CUWORhdetailModelIRREMd.data.apr floatValue] * [self.CUWORhdetailModelIRREMd.data.timeLimitDay integerValue] / 365 / 100];
    [self.DqlqILaprLabelIPueGU sizeToFit];
    self.DqlqILaprLabelIPueGU.centerX = self.KfiJgNaccountTextFieldQccsSJ.centerX;
    self.DqlqILaprLabelIPueGU.top = self.ruler.centerY + 10;
    if (self.umUnmiamount) {
        self.umUnmiamount(self.KfiJgNaccountTextFieldQccsSJ.text);
    }
}

- (void)rulerRunEnd
{
    if (self.ruleEnd) {
        self.ruleEnd();
    }
}

- (CAShapeLayer *)addLineOriginPoint:(CGPoint)p0 toPoint:(CGPoint)p1 color:(UIColor *)color borderWidth:(CGFloat)borderWidth {
    
    /// 线的路径
    UIBezierPath * bezierPath = [UIBezierPath bezierPath];
    [bezierPath moveToPoint:p0];
    [bezierPath addLineToPoint:p1];
    
    CAShapeLayer * ZLmcEJshapeLayerWDClkp = [CAShapeLayer layer];
    ZLmcEJshapeLayerWDClkp.strokeColor = color.CGColor;
    ZLmcEJshapeLayerWDClkp.fillColor  = [UIColor clearColor].CGColor;
    /// 添加路径
    ZLmcEJshapeLayerWDClkp.path = bezierPath.CGPath;
    /// 线宽度
    ZLmcEJshapeLayerWDClkp.lineWidth = borderWidth;
    return ZLmcEJshapeLayerWDClkp;
}

- (BOOL)dZrvUEtextFieldRRHEAtShouldReturn:(UITextField *)dZrvUEtextFieldRRHEAt{
    if ([dZrvUEtextFieldRRHEAt.text integerValue] > [self.CUWORhdetailModelIRREMd.data.remmoney integerValue]) {
        [self.ruler scrollToValue:[self.CUWORhdetailModelIRREMd.data.remmoney integerValue] animation:YES];
    } else if ([dZrvUEtextFieldRRHEAt.text integerValue] < [self.CUWORhdetailModelIRREMd.data.lowestAccount integerValue]) {
        [self.ruler scrollToValue:[self.CUWORhdetailModelIRREMd.data.lowestAccount integerValue] animation:YES];
    } else {
        [self.ruler scrollToValue:[dZrvUEtextFieldRRHEAt.text integerValue] animation:YES];
    }
    return [dZrvUEtextFieldRRHEAt resignFirstResponder];
}

- (void)dZrvUEtextFieldRRHEAtDidEndEditing:(UITextField *)dZrvUEtextFieldRRHEAt {
    if ([dZrvUEtextFieldRRHEAt.text integerValue] > [self.CUWORhdetailModelIRREMd.data.remmoney integerValue]) {
        [self.ruler scrollToValue:[self.CUWORhdetailModelIRREMd.data.remmoney integerValue] animation:YES];
    } else if ([dZrvUEtextFieldRRHEAt.text integerValue] < [self.CUWORhdetailModelIRREMd.data.lowestAccount integerValue]) {
        [self.ruler scrollToValue:[self.CUWORhdetailModelIRREMd.data.lowestAccount integerValue] animation:YES];
    } else {
        [self.ruler scrollToValue:[dZrvUEtextFieldRRHEAt.text integerValue] animation:YES];
    }
}


- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
